<template>
  <div class="box">
    <van-nav-bar
      title="京东注册"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="input" style="padding: 50px 0px">
      <van-form @submit="onSubmit">
        <!-- 可以使用 CellGroup 作为容器 -->
        <van-cell-group inset>
          <van-field
            v-model="value"
            label="密码"
            placeholder="至少6位,包含数字,大小写字母"
          />
        </van-cell-group>
        <div style="margin: 80px 10px">
          <van-button round block type="primary" native-type="submit">
            完成
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { showDialog } from "vant";
import { reigstok } from "../../service/regist";
export default {
  data() {
    return {
      value: "",
    };
  },
  methods: {
    //路由回退
    onClickLeft() {
      history.back();
    },
    //提交密码
    //完成注册
    onSubmit() {
      reigstok({ tel: `${this.$store.state.tel}`, password: this.value }).then(
        (res) => {
          console.log(res);
          if (res.data.code === "200") {
            showDialog({
              title: "注册完成",
              message: "恭喜注册完成",
            }).then(() => {
              this.$router.push("/login")
            });
          }
        }
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  background-color: #f5f5f5;
  height: 100vh;
}
.input {
  margin: 10px;
}
</style>
